import pandas as pd
import matplotlib.pyplot as plt


plt.rcParams['font.sans-serif'] = 'SimHei'  # 设置字体为SimHei
plt.rcParams['axes.unicode_minus'] = False  # 解决负号“-”显示异常

data = pd.read_excel('data.xlsx')
# 根据产品计算利润额，第一步获取所有产品类别
all_product = data.loc[:, '产品'].unique()

sizes = []
labels = []
for product in all_product:
    product_profit = data.loc[data['产品'] == product, '利润额']
    profit_sum = product_profit.sum()
    sizes.append(profit_sum)
    labels.append(product)

plt.pie(sizes, labels = labels, autopct='%1.1f%%', startangle=90, wedgeprops={'width':0.3})
plt.show()